<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">所属项目id</label>
        <el-input v-model="query.projectId" clearable placeholder="所属项目id" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">所属项目名称</label>
        <el-input v-model="query.projectName" clearable placeholder="所属项目名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">排序</label>
        <el-input v-model="query.orderNumber" clearable placeholder="排序" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="工单名称" prop="workName">
            <el-input v-model="form.workName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工单描述" prop="workDescrible">
            <el-input v-model="form.workDescrible" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="工单编号" prop="workCode">
            <el-input v-model="form.workCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属项目id" prop="projectId">
            <el-input v-model="form.projectId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="所属项目名称" prop="projectName">
            <el-input v-model="form.projectName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="排序">
            <el-input v-model="form.orderNumber" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="info" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table border stripe highlight-current-row stripe ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column align="center" prop="workName" label="工单名称" />
        <el-table-column align="center" prop="workCode" label="工单编号" />
        <el-table-column align="center" prop="projectName" label="所属项目名称" />
        <el-table-column align="center" prop="orderNumber" label="排序" />
        <el-table-column align="center" prop="remark" label="备注" />
        <el-table-column align="center" prop="createBy" label="创建者" />
        <el-table-column align="center" prop="updateBy" label="更新者" />
        <el-table-column align="center" prop="createTime" label="创建日期" />
        <el-table-column align="center" prop="updateTime" label="更新时间" />
        <el-table-column v-if="checkPer(['admin','workOrderHead:edit','workOrderHead:del'])" label="操作" width="200px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
  import crudWorkOrderHead from '@/api/workOrder/workOrderHead'
  import CRUD, { presenter, header, form, crud } from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'

  const defaultForm = { workId: null, workName: null, workDescrible: null, workCode: null, projectId: null, projectName: null, orderNumber: null, remark: null, isDelete: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
  export default {
    name: 'WorkOrderHead',
    components: { pagination, crudOperation, rrOperation, udOperation },
    mixins: [presenter(), header(), form(defaultForm), crud()],
    cruds() {
      return CRUD({ title: '工单头', url: 'api/workOrderHead', idField: 'workId', sort: 'orderNumber,desc', crudMethod: { ...crudWorkOrderHead }})
    },
    data() {
      return {
        permission: {
          add: ['admin', 'workOrderHead:add'],
          edit: ['admin', 'workOrderHead:edit'],
          del: ['admin', 'workOrderHead:del']
        },
        rules: {
          workName: [
            { required: true, message: '工单名称不能为空', trigger: 'blur' }
          ],
          workDescrible: [
            { required: true, message: '工单描述不能为空', trigger: 'blur' }
          ],
          workCode: [
            { required: true, message: '工单编号不能为空', trigger: 'blur' }
          ],
          projectId: [
            { required: true, message: '所属项目id不能为空', trigger: 'blur' }
          ],
          projectName: [
            { required: true, message: '所属项目名称不能为空', trigger: 'blur' }
          ]
        },
        queryTypeOptions: [
          { key: 'projectId', display_name: '所属项目id' },
          { key: 'projectName', display_name: '所属项目名称' },
          { key: 'orderNumber', display_name: '排序' }
        ]
      }
    },
    methods: {
      // 钩子：在获取表格数据之前执行，false 则代表不获取数据
      [CRUD.HOOK.beforeRefresh]() {
        return true
      }
    }
  }
</script>

<style scoped>

</style>
